
public class Area {
	public static void main(String[] args) {
		Area area = new Area();
		double[][] data = {{52.7, 22.9, 27.3, 13.3}, 
						  {68.8, 57.6, 23.2, 8.0}, 
						  {20.0, 48.0, 37.0, 23.5},
						  {41.5, 36.2, 27.3, 21.4}};
		
		
		double result;
		result = area.area(data);
		System.out.println(result);
	}

	private double area(double[][] data) {
		
		double result = 0;
		double uponX = 0;
		double uponY = 0 ;
		for(int i=0; i<4; i++) {
			result += data[i][2]*data[i][3];
			
		}
		for(int i=0; i<4; i++) {
			for(int j=i; j<4; j++) {
				if(data[i][0] < data[j][0] && (data[i][0]+data[i][2]) > data[j][0]) {
					if(data[i][1] < data[j][1] && (data[i][1]+data[i][3]) > data[j][1]){
						uponX = (data[i][0] + data[i][2]) - data[j][0];
						uponY = (data[i][1] + data[i][3]) - data[j][1];
						result -= Math.abs(uponX * uponY);
					}
					if(data[i][1] < (data[j][1]+ data[j][3]) && (data[i][1]+data[i][3]) > (data[j][1]+ data[j][3])){
						uponX = (data[i][0] + data[i][2]) - data[j][0];
						uponY = data[i][1]  - (data[j][1] + data[j][3]);
						result -= Math.abs(uponX * uponY);
					}
				}
			}
		}
		
		return result;
	}

	
}
